package com.dwyinyuan;

import com.dwyinyuan.consumer.Consumer;
import com.dwyinyuan.consumer.FileConsumer;
import com.dwyinyuan.enums.FileProviderEnums;
import com.dwyinyuan.enums.ProviderEnums;
import com.dwyinyuan.model.FileDTO;
import com.dwyinyuan.watch.ResourceListener;

import java.util.concurrent.*;

/**
 * 微信公众号：笛舞音缘
 * 入口
 */
public class SpiderApplication {

    public static void main(String[] args) {
        BlockingQueue<FileDTO> blockingQueue = new SynchronousQueue<>(true);//队列
        ExecutorService proservice = Executors.newSingleThreadExecutor();//生产者线程
        ExecutorService conservice = Executors.newSingleThreadExecutor();//消费者线程

        ExecutorService taskPool = Executors.newCachedThreadPool();

        proservice.submit(FileProviderEnums.getTaskByName(FileProviderEnums.BI_IB.getName(), blockingQueue));
        conservice.submit(new FileConsumer(blockingQueue, taskPool));

        proservice.shutdown();
        conservice.shutdown();

    }

    private void old() {
        ResourceListener.addListener("C:\\Users\\99478\\Downloads\\Music\\");//观察者模式

        BlockingQueue<String> blockingQueue = new SynchronousQueue<String>(true);//队列
        ExecutorService proservice = Executors.newSingleThreadExecutor();//生产者线程
        ExecutorService conservice = Executors.newSingleThreadExecutor();//消费者线程

        ExecutorService taskPool = Executors.newCachedThreadPool();

        String providerName = "FengniaoProducer";

        proservice.submit(ProviderEnums.getTaskByName(providerName, blockingQueue));//V3
        conservice.submit(new Consumer("Consumer", blockingQueue, taskPool));

        proservice.shutdown();
        conservice.shutdown();
    }


}
